package com.erp.order.purchasing.controller;

import com.erp.hr.base.controller.BaseController;
import com.erp.hr.base.vo.ResultVO;
import com.erp.order.purchasing.model.PurchasingRequisitionDetail;
import com.erp.order.purchasing.service.PurchasingRequisitionDetailService;
import org.redragon.framework.hibernate.model.Pages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.validation.Valid;
import java.util.List;

/**
 * 采购申请详情 控制层
 * @Author: syz
 * @blame syz
 * @CreateTime: 2021/4/6
 */
@Controller
@RequestMapping("web/purchasingRequisitionDetail")
public class PurchasingRequisitionDetailController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(PurchasingRequisitionDetailController.class);

    /**
     * 采购申请服务
     */
    @Autowired
    private PurchasingRequisitionDetailService purchasingRequisitionDetailService;


    /**
     * 获取可合并列表分页数据
     * @param pages 分页对象
     * @param purchasingRequisitionDetail 申请详情对象
     * @param model 模型对象
     * @return 页面路径
     */
    @RequestMapping("getSubPageList")
    public String getSubPageList(Pages pages, PurchasingRequisitionDetail purchasingRequisitionDetail, Model model) {
        purchasingRequisitionDetail.setBuyer(getStaffInfo().getStaffCode());
        model.addAttribute("pages", setPages(pages));
        model.addAttribute("list", purchasingRequisitionDetailService.getDataObjectsForDataAuth("", pages, purchasingRequisitionDetail));
        model.addAttribute("unitMap", purchasingRequisitionDetailService.getDictByKey("material_unit"));
        return "inquiryList/materialPop";
    }

    /**
     * 根据条件查询申请详情集合
     * @param purchasingRequisitionDetail 申请详情对象
     * @return 申请详情集合
     */
    @ResponseBody
    @RequestMapping("getList")
    public List<PurchasingRequisitionDetail> getList(@RequestBody PurchasingRequisitionDetail purchasingRequisitionDetail) {
        return purchasingRequisitionDetailService.getDataObjects(purchasingRequisitionDetail);
    }

    /**
     * 新增/编辑
     * @param purchasingRequisitionDetail 需要新增/编辑的对象
     * @return 新增/编辑结果
     */
    @ResponseBody
    @RequestMapping("save")
    public ResultVO<String> save(@Valid @RequestBody PurchasingRequisitionDetail purchasingRequisitionDetail) {
        return saveOrUpdate(purchasingRequisitionDetailService, purchasingRequisitionDetail);
    }

    /**
     * 删除
     * @param id 需要删除对象的id
     * @return 删除结果
     */
    @ResponseBody
    @RequestMapping("del")
    public ResultVO<String> del(Long id) {
        return linkDelete(purchasingRequisitionDetailService, id);
    }

}